Skip to content

Conversation

@Alann27
Copy link
Contributor

@Alann27 Alann27 commented Sep 25, 2025

Summary

  • Added new table creation logic for staked_suppliers_by_block_and_services, staked_apps_by_block_and_services, and relay_by_block_and_services, replacing unique index and upsert constraints to avoid unnecessary overhead.
  • Implemented retry utility for handling module accounts and integrated it into handleModuleAccounts.
  • Enhanced block report generation by running database functions in parallel for performance improvements.
  • Refined block processing in handleBlock to include timing logs for profiling purposes.

Issue

In beta, we have more than 10,000 services. This caused the indexer to take over 30 seconds to index a single block due to the heavy load from reports by block and services.

The tables

  • staked_suppliers_by_block_and_services
  • staked_apps_by_block_and_services
  • relay_by_block_and_services

were being created through SubQL (since they were defined in schema.graphql). Because historical data was enabled, these tables included the _block_range column, and SubQL automatically generated compound indexes for each foreign key combined with _block_range.

However, historical data does not apply to these tables, since we insert new records for every block. This means we don’t need the _block_range column or the additional indexes created by SubQL.

With this change, the indexer now takes around 5 seconds to index a block (down from 30+ seconds).


We also encountered an issue when fetching module accounts: queries sometimes returned no results for the block being indexed. To address this, we added a retry mechanism that keeps querying for module accounts until they become available or the retry limit is reached.

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@Alann27 Alann27 requested a review from jorgecuesta September 25, 2025 17:49
…ervices`, `staked_apps_by_block_and_services`, and `relay_by_block_and_services`, replacing unique index and upsert constraints to avoid unnecessary overhead.

- Implemented retry utility for handling module accounts and integrated it into `handleModuleAccounts`.
- Enhanced block report generation by running database functions in parallel for performance improvements.
- Refined block processing in `handleBlock` to include timing logs for profiling purposes.
@Alann27 Alann27 force-pushed the refactor-reports-by-block-and-services branch from 4d470ae to 20796dd Compare September 25, 2025 17:50
@jorgecuesta jorgecuesta merged commit 328e0d2 into main Sep 25, 2025
3 checks passed
@jorgecuesta jorgecuesta deleted the refactor-reports-by-block-and-services branch September 25, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants